import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2025-03-12
 * Time: 20:27
 */
public class test1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n=scanner.nextInt();
        if(n==0){
            System.out.println(0);
            return;
        }
        //arr为斐波那契数列
        int[] arr=new int[n];
        arr[0]=0;
        arr[1]=1;
        int i=1;
        while(arr[i]<n){
            arr[i+1]=arr[i]+arr[i-1];
            i++;
        }
        int a=arr[i]-n;
        int b=n-arr[i-1];
        if(a>b){
            System.out.println(b);
        }else {
            System.out.println(a);
        }


    }
}
